#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;

unshift(@INC, '.');
require qpdf_test_helpers;

chdir("qpdf") or die "chdir testdir failed: $!\n";

require TestDriver;

cleanup();

my $td = new TestDriver('extensions-dictionary');

my @ext_inputs = ('minimal.pdf', 'extensions-adbe.pdf',
                  'extensions-other.pdf', 'extensions-adbe-other.pdf');
my @new_versions = ('1.3', '1.6', '1.7.1', '1.7.2', '1.7.3',
                    '1.8', '1.8.0', '1.8.2', '1.8.5');
my $n_tests = (4 * @new_versions + 3) * @ext_inputs;
foreach my $input (@ext_inputs)
{
    my $base = $input;
    $base =~ s/\.pdf$//;
    if ($base eq 'minimal')
    {
        $base = 'extensions-none';
    }
    foreach my $version (@new_versions)
    {
        foreach my $op (qw(min force))
        {
            $td->runtest("$input: $op version to $version",
                         {$td->COMMAND =>
                              "qpdf --static-id" .
                              " --$op-version=$version $input a.pdf"},
                         {$td->STRING => "", $td->EXIT_STATUS => 0});
            $td->runtest("check version information ($op $version)",
                         {$td->COMMAND => "test_driver 34 a.pdf"},
                         {$td->FILE => "$base-$op-$version.out",
                          $td->EXIT_STATUS => 0},
                         $td->NORMALIZE_NEWLINES);
            if (($op eq 'force') && ($version eq '1.8.5'))
            {
                # Look at the actual file for a few cases to make sure
                # qdf and non-qdf output are okay
                $td->runtest("check file",
                             {$td->COMMAND => "qpdf-test-compare a.pdf $base-$op-$version.pdf"},
                             {$td->FILE => "$base-$op-$version.pdf", $td->EXIT_STATUS => 0});
                $td->runtest("$input: $op version to $version",
                             {$td->COMMAND =>
                                  "qpdf --qdf --static-id" .
                                  " --$op-version=$version $input a.qdf"},
                             {$td->STRING => "", $td->EXIT_STATUS => 0});
                $td->runtest("check file",
                             {$td->COMMAND => "qpdf-test-compare a.qdf $base-$op-$version.qdf"},
                             {$td->FILE => "$base-$op-$version.qdf", $td->EXIT_STATUS => 0});
            }
        }
    }
}
cleanup();
$td->report($n_tests);
